if(${ENABLE_TESTS})
  set(test_sources)
  if(test IN_LIST libs_to_build)
    # Create a list of imported directories to include during libtest build
    set(test_imported_include_directories)
    foreach(libname ${dy1-libs} ${dy1-contrib-libs})
      list(APPEND test_imported_include_directories $<TARGET_PROPERTY:${libname},INTERFACE_INCLUDE_DIRECTORIES>)
    endforeach()

    # Import include directories of dependencies to build libtest
    target_include_directories(${libtest} PUBLIC ${test_imported_include_directories})
    unset(test_imported_include_directories)

    # Define the libtest as an object to build test-runner
    set(test_sources $<TARGET_OBJECTS:${libtest}>)
  endif()

  if(WIN32)
    # DLL linking shenanigans prevent loading symbols unused by a certain program,
    # so link the tests libraries (here built as objects) directly to the test runner
    add_executable(test-runner test-runner.cc ${dy1-libs-tests} ${test_sources})
    if(${DY1_MONOLIB})
      target_link_libraries(
              test-runner ${lib-dy1-monolib} ${dy1-contrib-libs}
      )
    else()
      target_link_libraries(
              test-runner ${dy1-libs} ${dy1-contrib-libs}
      )
    endif()
  else()
    add_executable(test-runner ${test_sources} test-runner.cc)

    if(${DY1_MONOLIB})
      target_link_libraries(
        test-runner ${LIB_AS_NEEDED_PRE} ${dy1-libs-tests} ${lib-dy1-monolib} ${dy1-contrib-libs} ${LIB_AS_NEEDED_POST}
      )
    else()
      target_link_libraries(
        test-runner ${LIB_AS_NEEDED_PRE} ${dy1-libs-tests} ${dy1-libs} ${dy1-contrib-libs} ${LIB_AS_NEEDED_POST}
      )
    endif()
  endif()
  set_runtime_outputdirectory(
    test-runner ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/utils/ ""
  )
  add_dependencies(test-runner test-runner-examples-as-tests)
  add_dependencies(all-test-targets test-runner)
endif()

add_subdirectory(googletest)


